package configx

import (
	"os"

	"github.com/go-kratos/kratos/v2"
	"github.com/go-kratos/kratos/v2/log"
	"github.com/go-kratos/kratos/v2/middleware/tracing"
	"github.com/go-kratos/kratos/v2/transport/grpc"
	"github.com/google/wire"
)

// go build.sh -ldflags "-X main_test.go.Version=x.y.z"
var (
	// Name is the name of the compiled software.
	Name string = "GinRouter"
	// Version is the version of the compiled software.
	Version string = "1.0.0"
	id, _          = os.Hostname()
)
var Logger = log.With(log.NewStdLogger(os.Stdout),
	"ts", log.DefaultTimestamp,
	"caller", log.DefaultCaller,
	"service.id", id,
	"service.name", Name,
	"service.version", Version,
	"trace.id", tracing.TraceID(),
	"span.id", tracing.SpanID(),
)

func NewApp(logger log.Logger, server *grpc.Server) *kratos.App {
	return kratos.New(
		kratos.ID(id),
		kratos.Name(Name),
		kratos.Version(Version),
		kratos.Metadata(map[string]string{}),
		kratos.Logger(logger),
		kratos.Server(
			server,
		),
	)
}

var ProviderSet = wire.NewSet(NewApp)
